<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
    <h4 class="modal-title">{{{ trans('permission.set-permission') }}} - "{{{ @$Object->display_name }}}"</h4>
</div>
<div class="portlet modal-body portlet-body form">
    <!-- BEGIN FORM-->
    <form action="{{ $url }}" class="form-horizontal" id="form-options" method="post">
        <div class="form-body">
            <div class="alert alert-danger display-hide">
                <button class="close" data-close="alert"></button>
                {{ trans('validation.custom.error-title') }}
            </div>
            <div class="alert alert-success display-hide">
                <button class="close" data-close="alert"></button>
                <span>{{ trans('validation.custom.success-title') }}</span>
            </div>
            <div class="form-group" style="margin-left: 0; margin-right: 0;">
                <label class="control-label col-md-4" for="role_group_id">{{{ trans('permission.role.name') }}}<span class="required">*</span></label>
                <div class="col-md-8">
                    <select name="role_group_id[]" data-placeholder="{{trans('system.select')}}..." class="form-control chosen" multiple="multiple" style="width: 500px;" tabindex="10000"> 
                        @foreach ($Roles as $role) 
                        <option value="{{{$role->id}}}" {{{ in_array($role->name, $permission_role_names) ? 'selected="selected"' : null }}}>{{$role->name}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-left: 0; margin-right: 0;">
                <label class="control-label col-md-4" for="role_personal_id">{{{ trans('permission.role.personal') }}}<span class="required">*</span></label>
                <div class="col-md-8">
                    <select name="role_personal_id[]" data-placeholder="{{trans('system.select')}}..." class="form-control chosen" multiple="multiple" style="width: 500px;" tabindex="10000">
                        @foreach ($Users as $user) 
                        <option value="{{{$user->id}}}" {{{ in_array($user->id, $permission_role_names) ? 'selected="selected"' : null }}}>{{$user->id}} - {{$user->saint}} {{$user->username}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
        </div>
    </form>
    <!-- END FORM-->
</div>
<div class="modal-footer">
    <button type="button" class="btn default btn-close-modal" data-dismiss="modal">{{ trans('system.button.cancel') }}</button>
    <button type="button" class="btn blue btn-new-options">{{ trans('system.button.submit') }}</button>
</div>
<script type="text/javascript">
    $(".chosen").each(function() {
        $(this).chosen({
            allow_single_deselect: $(this).attr("data-with-deselect") == "1" ? true : false
        });
    });

    var form = $('#form-options');
    var error = $('.alert-danger', form);
    var success = $('.alert-success', form);

    $('.btn-new-options').click(function() {

        $.ajax({
            url: form.attr('action'),
            type: form.attr('method'),
            data: form.serialize(),
            dataType: 'json'
        }).done(function(response) {
            if (response.status == 200) {
                success.find('span').text(response.message);
                success.show();
                error.hide();
                $('.btn-close-modal').click();
            }
            else {
                error.find('span').text(response.message);
                error.show();
                success.hide();
            }
        })
                .fail(function() {
                    error.find('span').text('Check Your Connection.');
                    error.show();
                    success.hide();
                });
    });
</script>